import { ParamsType, ProColumns, RequestData } from "@ant-design/pro-components";
import { SortOrder } from "antd/es/table/interface";
import React, { FC } from "react";


/**
 * 编辑项类型
 */
export type ReacordType = 'input' | 'select' | 'checkbox' | 'radio' | 'switch';

/**
 * 编辑项属性（编辑table item的配置）
 */
export interface RecordAttr<T> {
    type?: ReacordType;
    option?: Array<any>;
    customComponent?: (record: T) => React.ReactNode;
}

/**
 * 列属性基础类型
 */
export interface LpProTableBaseColumnType<T> {
    id: any;
    attr?: RecordAttr<T>;
}

/**
 * 列属性类型
 */
export type LpProTableColumnsType<T> = Array<ProColumns<T> & { attr?: RecordAttr<T> }>;

/**
 *  表格props 类型
 */
export interface LpProTableProps<T extends LpProTableBaseColumnType<T>> {
    /**
     * 表格 列list
     */
    columns: LpProTableColumnsType<T>;
    /**
     * tab 自定义区
     */
    toolBarRender?: React.ReactNode[];
    /**
     * 获取table数据
     * @param params
     * @param sort
     * @param filter
     * @returns
     */
    getTableData: (
        params: ParamsType & {
            pageSize?: number | undefined;
            current?: number | undefined;
            keyword?: string | undefined;
        },
        sort?: Record<string, SortOrder>,
        filter?: Record<string, (string | number)[] | null>,
    ) => Promise<Partial<RequestData<T>>>;
    /**
     * 删除table item项
     * @param id
     * @returns
     */
    deleteTableItem: (id: number) => Promise<any>;
    /**
     * 新增table item项
     * @param record
     * @returns
     */
    addTableItem: (record: Partial<T>) => Promise<any>;
    /**
     * 更新table item项
     */
    updateTableItem: (record: Partial<T>) => Promise<any>;
}
